package com.czxy.mapper;

import com.czxy.pojo.Spec;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author 张青卯
 */
@org.apache.ibatis.annotations.Mapper
public interface SpecMapper extends Mapper<Spec> {

    /**
     * findSpecificationByCategoryId 查询品牌
     * @param cat3id 商品ID
     * @return List<Spec>
     */
    @Select("select * from tb_specification where categoryId = #{cat3id}")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "specName",column = "specName"),
            @Result(property = "categoryId",column = "categoryId"),
            @Result(property = "options",column = "id",many = @Many(select = "com.czxy.mapper.SpecOptionMapper.findSpecificationOptionBySpecificationId"))
    })
    List<Spec> findSpecificationByCategoryId(Integer cat3id);

    @Select("select * from tb_specification where id = #{specId}")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "specName",property = "specName"),
            @Result(column = "categoryId",property = "categoryId"),
            @Result(column = "id",property = "options",many = @Many(select = "com.czxy.mapper.SpecOptionMapper.findSpecificationOptionBySpecid"))
    })
    Spec findSpecificationBySpecid(Integer specId);
}
